package com.shhm.admin.controller;

import com.shhm.admin.service.UserService;
import com.shhm.common.annotations.OperateLog;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.entity.admin.SysUser;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackZ
 * @version 1.0
 * @description: 用户管理api
 * @date 2025/8/1 下午2:33
 */
@RestController
@RequestMapping("/admin")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/user/list")
    public AjaxResultPlus UserList(){
        return userService.userList();
    }

    @GetMapping("/user")
    public AjaxResultPlus pageList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            HttpServletRequest request
    ){
        return userService.pageList(pageNum,pageSize,request);
    }
    @PostMapping("/user/search")
    public AjaxResultPlus pageSearchList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody SysUser user
    ){
        return userService.pageSearchList(pageNum,pageSize,user);
    }

    @PostMapping("/user")
    @OperateLog(module="用户管理",type = "POST",desc = "添加用户账号信息")
    public AjaxResultPlus add(@RequestBody SysUser user){
        return userService.add(user);
    }

    @PutMapping("/user")
    @OperateLog(module="用户管理",type = "PUT",desc = "修改用户账号信息")
    public AjaxResultPlus update(@RequestBody SysUser user){
        return userService.update(user);
    }

    @DeleteMapping("/user")
    @OperateLog(module="用户管理",type = "DELETE",desc = "删除用户账号")
    public AjaxResultPlus delete(@RequestBody RequestList ids){
        return userService.delete(ids);
    }
}
